package demo.DataStrucAndAlgo.Easy_pritice;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @Auther: hjy(lc))
 * @Date: 2022/10/18-10-18-22:02
 * @Description：demo.DataStrucAndAlgo.Easy_pritice
 */
public class Test_qianFeng {
    public static void main(String[] args) {
//        int[] arr = {10,56,23,9,78,17};
//        SelectSort(arr);
//        System.out.println(Arrays.toString(arr));
        Map<String,Integer> map = new HashMap<>();
        for (int i = 0; i < 5; i++) {
            map.put("hello"+i,i);
        }

        System.out.println("``````````````````方式一：keySet`````````````````");
        //第一种遍历方式   keySet
        Set<String> strings = map.keySet();
        for (String string : strings) {
            System.out.println(string  + "= " + map.get(string));
        }
        System.out.println("=======================方式二：entrySet========================");
        //第二种方式
        Set<Map.Entry<String, Integer>> entries = map.entrySet();
        for (Map.Entry<String, Integer> entry : entries) {
            System.out.println(entry.getKey() + " = " + entry.getValue());
        }
        System.out.println("-----------------------方式三：lambada表达式-------------------------");
        //第三种方式
        map.forEach((k,v)-> System.out.println(k + " = " + v));
    }


    /**
     * 每一次排序中，在待排序元素中找到最小值，放到第i号位置    i从0~n-1
     * @param arr
     */
    public static void SelectSort(int[] arr) {
        int index = 0,temp;
        for (int i = 0; i < arr.length - 1; i++) {
            index = i;
            for (int j = i+1; j < arr.length; j++) {
                if(arr[j] < arr[index]){
                    index = j;
                }
            }
            temp = arr[i];              //将第i号位置替换成最小值
            arr[i] = arr[index];
            arr[index] = temp;
        }
    }
}


